package com.jckj.core.config;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import com.jckj.core.util.SpringContextHolder;
import com.jckj.core.vos.LoginUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.*;

import java.util.Properties;

/**
 * SpringConfig.class
 *
 * @author 刘志远
 * @date 2017-12-18
 */
@Configuration
@Import({JdbcConfig.class,AopConfig.class,ServiceConfig.class,ShiroConfig.class, TaskConfig.class})
public class SpringConfig {

    @Autowired
    ApplicationContext applicationContext;

    @Bean
    @Lazy(false)
    public SpringContextHolder springContextHolder(){
        SpringContextHolder contextHolder = new SpringContextHolder();
        contextHolder.setApplicationContext(applicationContext);
        return contextHolder;
    }

    @Bean
    public DefaultKaptcha kaptcha(){
        Properties pro = new Properties();
        pro.setProperty("kaptcha.textproducer.font.color", "blue");
        pro.setProperty("kaptcha.textproducer.font.size", "45");
        pro.setProperty("kaptcha.image.width", "125");
        pro.setProperty("kaptcha.image.height", "45");
        pro.setProperty("kaptcha.textproducer.char.length", "4");
        pro.setProperty("kaptcha.textproducer.font.names", "宋体,楷体,微软雅黑");
        Config config = new Config(pro);
        DefaultKaptcha kaptcha = new DefaultKaptcha();
        kaptcha.setConfig(config);
        return kaptcha;
    }

    @Bean
    @Scope(value="session", proxyMode=ScopedProxyMode.TARGET_CLASS)
    public LoginUserVo loginUser(){
        LoginUserVo vo = new LoginUserVo();
        return vo;
    }
}
